package ${controllerPkg};

<#compress>
<#if GeneratorInfo.hasSwagger == "1">
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
</#if>

import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.lycode.common.core.controller.BaseController;
import cn.lycode.common.core.domain.AjaxResult;
import cn.lycode.common.core.page.PageResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import cn.lycode.common.core.domain.model.SelectIdsDTO;

import ${servicePkg}.${serviceClassName};
import ${dtoPkg}.${dtoAddClassName};
import ${dtoPkg}.${dtoUpdateClassName};
import ${dtoPkg}.${dtoListClassName};
import ${voPkg}.${voClassName};
<#if GeneratorInfo.hasImport == "1">
import org.springframework.web.multipart.MultipartFile;
</#if>
<#if GeneratorInfo.hasExport == "1">
import jakarta.servlet.http.HttpServletResponse;
</#if>
</#compress>


/**
 * ${tableComment} Controller
 * @since ${datetime}
 * @author ${author}
 */
<#if GeneratorInfo.hasSwagger == "1">
@Tag(name =  "${tableComment}")
</#if>
@RestController
@RequestMapping("/${router}")
@RequiredArgsConstructor
public class ${controllerClassName}  extends BaseController{

<#assign serviceName = lower_case_first_letter(serviceClassName)>
    private final ${serviceClassName} ${serviceName};

    //列表分页条件查询
<#if GeneratorInfo.hasSwagger == "1">
    @Operation(summary = "列表查询")
</#if>
    @SaCheckPermission(value = "${listPermission}")
    @GetMapping("/list")
    public AjaxResult<PageResult<${voClassName}>> listPage(${dtoListClassName} dto) {
        return AjaxResult.success(${serviceName}.listPage(dto));
    }

    //新增
<#if GeneratorInfo.hasSwagger == "1">
    @Operation(summary = "新增")
</#if>
<#if GeneratorInfo.btnPermissionType == "1">
    @SaCheckPermission(value = "${addPermission}")
</#if>
    @PostMapping("/add")
    public AjaxResult<Object> add(@Valid @RequestBody ${dtoAddClassName} dto) {
        return toAjax(${serviceName}.add(dto));
    }

    //详情
<#if GeneratorInfo.hasSwagger == "1">
    @Operation(summary = "详情")
</#if>
<#if GeneratorInfo.btnPermissionType == "1">
    @SaCheckPermission(value = "${listPermission}")
</#if>
    @GetMapping("/{id}")
    public AjaxResult<${voClassName}> detail(@PathVariable Long id) {
    return AjaxResult.success(${serviceName}.detail(id));
    }

    //修改
<#if GeneratorInfo.hasSwagger == "1">
    @Operation(summary = "修改")
</#if>
<#if GeneratorInfo.btnPermissionType == "1">
    @SaCheckPermission(value = "${updatePermission}")
</#if>
    @PostMapping("/update")
    public AjaxResult<Object> update(@RequestBody ${dtoUpdateClassName} dto) {
        return toAjax(${serviceName}.update(dto));
    }

    //删除
<#if GeneratorInfo.hasSwagger == "1">
    @Operation(summary = "删除")
</#if>
<#if GeneratorInfo.btnPermissionType == "1">
    @SaCheckPermission(value = "${removePermission}")
</#if>
    @PostMapping("/remove")
    public AjaxResult<Object> remove(@RequestBody SelectIdsDTO dto) {
        ${serviceName}.remove(dto);
        return AjaxResult.success();
    }


<#if GeneratorInfo.hasImport == "1">
    //导入
<#if GeneratorInfo.hasSwagger == "1">
    @Operation(summary = "导入")
    @Parameters({
    @Parameter(name = "file", description = "上传文件", schema = @Schema(type = "string", format = "binary"), required = true),
    })
</#if>
    <#if GeneratorInfo.btnPermissionType == "1">
    @SaCheckPermission(value = "${importPermission}", orRole = GlobalConstant.SUPER_ROLE)
    </#if>
    @PostMapping("/import")
    public void importExcel(MultipartFile file) {
        ${serviceName}.importExcel(file);
    }
</#if>


<#if GeneratorInfo.hasExport == "1">
    //导出
<#if GeneratorInfo.hasSwagger == "1">
    @Operation(summary = "导出")
</#if>
  <#if GeneratorInfo.btnPermissionType == "1">
    @SaCheckPermission(value = "${exportPermission}", orRole = GlobalConstant.SUPER_ROLE)
  </#if>
    @PostMapping("/export")
    public void exportExcel(@RequestBody ${dtoListClassName} dto, HttpServletResponse response) {
        ${serviceName}.exportExcel(dto, response);
    }
</#if>
<#compress>
}
<#-- 内建函数，实现首字母小写 -->
<#function lower_case_first_letter str>
    <#return str?substring(0, 1)?lower_case + str?substring(1)>
</#function>
</#compress>